package com.example.controller;

import com.example.entity.EasybuyProduct;
import com.example.entity.EasybuyProductCategory;
import com.example.service.EasybuyProductService;
import com.example.util.RespBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class EasybuyProductController {

    @Autowired
    public EasybuyProductService easybuyProductService;

    @RequestMapping(value = "query")
    public RespBean query(){
        List<EasybuyProductCategory> query = easybuyProductService.query();
        return RespBean.ok("查询成功",query);
    }
    @RequestMapping(value = "find")
    public RespBean find(@RequestParam(value = "id",defaultValue = "0") Integer id,
                        @RequestParam(value = "id2",defaultValue = "0") Integer id2,
                        @RequestParam(value = "id3",defaultValue = "0") Integer id3){
        if (id != 0){
            List<EasybuyProduct> query1 = easybuyProductService.query1(id);
            return RespBean.ok("查询成功",query1);
        }else if (id2 != 0){
            List<EasybuyProduct> query2 = easybuyProductService.query2(id2);
            return RespBean.ok("查询成功",query2);
        }else if (id3 != 0){
            List<EasybuyProduct> query3 = easybuyProductService.query3(id3);
            return RespBean.ok("查询成功",query3);
        }
        return RespBean.ok("查询成功");
    }
    @RequestMapping(value = "findById")
    public RespBean findById(@RequestParam(value = "id") Integer id){
        List<EasybuyProduct> byId = easybuyProductService.findById(id);
        return RespBean.ok("查寻成功",byId);

    }
}

